package com.eightywork.life.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;


import com.eightywork.life.model.Ad;
import com.eightywork.life.model.Comment;
import com.eightywork.life.model.Community;
import com.eightywork.life.model.Coupon;
import com.eightywork.life.model.Event;
import com.eightywork.life.model.Mtag;
import com.eightywork.life.model.Mtalks;
import com.eightywork.life.model.MyService;
import com.eightywork.life.model.Notice;
import com.eightywork.life.model.Pm;
import com.eightywork.life.model.PmView;
import com.eightywork.life.model.Space;
import com.eightywork.life.model.Tag;
import com.eightywork.life.model.Telephone;
import com.eightywork.life.util.*;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;

public class SpaceService extends BaseService {
	static final String URL = DOMAIN + "dapi/space.php";
	
	/*
	 * 2.28 更新推送token
	 */
	public static String updateToken(String uid, String token) throws MyHttpException {
		Map<String, String> params = new HashMap<String, String>();
		params.put("uid", uid);
		params.put("token", token);
		params.put("device", "android");
		params.put("client", "android");	
		params.put("m_auth", "");
		try {
			String json = HttpUtil.post(URL+"?do=push&op=add", params);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
			return jsonObject.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/*
	 * 1.29 删除推送token
	 * 
	 */
	public static String deleteToken(String uid, String token) throws MyHttpException {
		Map<String, String> params = new HashMap<String, String>();
		params.put("uid", uid);
		params.put("token", token);
		params.put("device", "android");
		params.put("client", "android");	
		params.put("m_auth", "");
		try {
			String json = HttpUtil.post(URL+"?do=push&op=remove", params);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.optBoolean("error")) {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			} else {
	//			System.out.println("----------调用取消token成功！------------->");
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	/**
	 * 1.28 未读通知数接口
	 * @return
	 * @throws MyHttpException
	 */
	public static long noticecount() throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "notice");
		map.put("op", "count");
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");	
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				return jsonObject.optJSONObject("data").optInt("new");
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return 0;
	}

	/**
	 * 推荐好友接口
	 * 
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Space> recommendFriend() throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "friend");
		map.put("view", "recommend");
		map.put("xiaoquid", CacheService.getSpace().getXiaoquid());
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");	
		List<Space> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Space>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 广告接口 xiaoquid: 小区id pagetype: 页面位置 getSpace().getmAuth(): API密钥,
	 * 由登录后返回的，客户端需要存储,每次调用接口需要使用此参数发到服务器
	 * 
	 * @param xiaoquid
	 * @param pagetype
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Ad> ad(String xiaoquid)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "ad");
		map.put("xiaoquid", xiaoquid);
		map.put("locateid", "1");
		List<Ad> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");	
				JSONObject jsonList = new JSONObject(data);
				String stringList = jsonList.optString("list");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(stringList, new TypeToken<List<Ad>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**1.3
	 * 动态列表接口 xiaoquid: 小区id【默认为空】 classid: 分类id【默认为空】 page: 当前页【默认1】 perpage:
	 * 每页数量【默认10】 keyword 关键词搜索【默认为空】
	 * 
	 * @param keyword
	 * @param longitude
	 * @param latitude
	 * @param span
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Community> home(String xiaoquid, String classid,
			String page, String perpage, String keyword, String uid)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "home");
		map.put("m_auth", "");
		map.put("client", "android");
		if (xiaoquid!=null)
			if(!xiaoquid.equals(""))
			map.put("xiaoquid", xiaoquid);
		if (classid!=null)
			map.put("classid", classid);
		if (!page.equals(""))
			map.put("page", page);
		if (!perpage.equals(""))
			map.put("perpage", perpage);
		if (!uid.equals(""))
			map.put("uid", uid);
		map.put("keyword", keyword);
		if (CacheService.isLogined())
		   map.put("m_auth", CacheService.getSpace().getmAuth());
		List<Community> list = null;
		
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");	
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Community>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**1.30.01
	 * 我参与的活动
	 *
	 * @throws MyHttpException
	 */
	public static List<Coupon> getMyCoupon(String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("do", "coupons");
		map.put("view", "apply");
		map.put("client", "android");
		map.put("page", page);
		map.put("perpage", perpage);
		List<Coupon> list = null;		
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				JSONObject jsonData = new JSONObject(data);
				String mslist = jsonData.optString("list");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(mslist, new TypeToken<List<Coupon>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	
	/**1.30.03
	 * 我参与的活动
	 *
	 * @throws MyHttpException
	 */
	public static List<Event> getMyEvent(String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("do", "event");
		map.put("view", "me");
		map.put("type", "all");
		map.put("client", "android");
		map.put("page", page);
		map.put("perpage", perpage);
		List<Event> list = null;		
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				JSONObject jsonData = new JSONObject(data);
				String mslist = jsonData.optString("list");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(mslist, new TypeToken<List<Event>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	
	
	/**1.32.03
	 * 获取我的预约服务列表
	 *
	 * @throws MyHttpException
	 */
	public static List<MyService> getMySerice(String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("do", "serviceapply");
		map.put("page", page);
		map.put("perpage", perpage);
		map.put("view", "me");
		map.put("client", "android");
		List<MyService> list = null;		
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				JSONObject jsonData = new JSONObject(data);
				String mslist = jsonData.optString("list");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(mslist, new TypeToken<List<MyService>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	
	

	/**
	 * 吐槽详情接口 talkid: 吐槽主键id
	 * 
	 * @param talkid
	 * @return
	 * @throws MyHttpException
	 */
	public static Community talk(String talkid) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "talk");
		map.put("talkid", talkid);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		
		Community community = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				community = gson.fromJson(data, Community.class);
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return community;
	}

	/**
	 * 1.5 获得分类接口
	 * 
	 * @return
	 * @throws MyHttpException
	 * m_auth:     API密钥, 由登录后返回的，客户端需要存储,每次调用接口需要使用此参数发到服务器 
	 */
	public static List<Tag> tagList() throws MyHttpException {
		long start = System.currentTimeMillis();
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "taglist");
		if (CacheService.isLogined()) {
			map.put("m_auth", CacheService.getSpace().getmAuth());
		} else {
			map.put("m_auth", "");
		}
		
		map.put("client", "android");
		List<Tag> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Tag>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		Log.d("tagList", System.currentTimeMillis() - start + "");
		return list;
	}

	/**
	 * 圈子列表接口 xiaoquid: 小区id
	 * 
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Mtag> mtag(String xiaoquid) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "mtag");
		map.put("xiaoquid", xiaoquid);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<Mtag> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Mtag>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 圈子吐槽列表接口 tagid: 圈子id page: 当前页【默认1】 perpage: 每页数量【默认10】 keyword: 搜索关键词
	 * 
	 * @param tagid
	 * @param page
	 * @param perpage
	 * @param keyword
	 * @return
	 * @throws MyHttpException
	 */
	public static Mtalks mtalkList(String id, String page,
			String perpage, String keyword) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "mtalk");
		map.put("op", "talklist");
		map.put("tagid", id);
		map.put("page", page);
		map.put("m_auth", "");
		map.put("client", "android");
		if (!perpage.equals(""))
			map.put("perpage", perpage);
		if (!keyword.equals(""))
			map.put("keyword", keyword);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		Mtalks mtalks = new Mtalks();
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			JSONObject data = jsonObject.optJSONObject("data");
			if (jsonObject.getInt("error") == 0) {
				String listString = data.optString("list");
				String pic = data.optString("pic");
				Gson gson = new GsonBuilder().serializeNulls().create();
				List<Community> list = gson.fromJson(listString, new TypeToken<List<Community>>() {
				}.getType());
				mtalks.setList(list);
				mtalks.setPic(pic);
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return mtalks;
	}

	/**
	 * 圈子吐槽详情接口
	 * 
	 * @param id圈子吐槽主键id
	 * @return
	 * @throws MyHttpException
	 */
	public static Community mtalk(String id) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "mtalk");
		map.put("id", id);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		Community talk = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				talk = gson.fromJson(data, Community.class);
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return talk;
	}

	/**
	 * 评论列表接口 id: 被评论的对象id idtype: 被评论的类型(photoid: 照片, 'blogid'：日志) page:
	 * 当前页，默认1 perpage: 每页数量，默认10 starttime: 取数据的开始时间，不包含变量自身, 默认空值不设置数据范围
	 * endtime: 取数据的结束时间，不包含变量自身, 默认空值不设置数据范围
	 * 
	 * @param id
	 * @param idtype
	 * @param page
	 * @param perpage
	 * @param starttime
	 * @param endtime
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Comment> comment(String id, String idtype, String page,
			String perpage, String starttime, String endtime)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "comment");
		map.put("id", id);
		map.put("idtype", idtype);
		map.put("page", page);
		map.put("perpage", perpage);
		map.put("starttime", starttime);
		map.put("endtime", endtime);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<Comment> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Comment>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 1.10  个人空间接口
	 * 
	 * @return
	 * @throws MyHttpException
	 */
	public static Space space(String uid) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("uid", uid);
		map.put("client", "android");
		if(CacheService.isLogined()) {
		     map.put("m_auth", CacheService.getSpace().getmAuth());	
		} else {
			map.put("m_auth", "");		
		}
		Space object = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {			
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				object = gson.fromJson(data, Space.class);
			} else {
//				System.out.println("==============" + jsonObject.optString("msg"));
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
				
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return object;
	}

	/**
	 * 1.11  对话列表接口 page 当前页【默认1】 perpage 每页数量【默认10】
	 * 
	 * @param page
	 * @param perpage
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Pm> pm(String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "pm");	
		map.put("perpage", perpage);
		map.put("page", page);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		
		List<Pm> list = null;
		try {
			String json = HttpUtil.get(URL, map);		
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {			
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Pm>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 1.12 对话详情接口 plid 对话列表中的主键id touid 对话列表中的touid
	 * 
	 * @param page
	 * @param perpage
	 * @param touid
	 * @return
	 * @throws MyHttpException
	 */
	public static List<PmView> pmView(String page, String perpage, String touid)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "pm");
		map.put("page", page);
		map.put("touid", touid);
		map.put("perpage", perpage);
		map.put("subop", "view");
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<PmView> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<PmView>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 *1.13 通知列表接口 page 当前页【默认1】 perpage 每页数量【默认10】
	 * 
	 * @param page
	 * @param perpage
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Notice> notice(String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "notice");
		map.put("page", page);
		map.put("perpage", perpage);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<Notice> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Notice>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	

	/**
	 * 1.15 好友列表接口 group: 分组id page: 当前页【默认1】 perpage:每页数量【默认10】
	 */
	public static List<Space> friend(String group, String page, String perpage)
			throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "friend");
		map.put("group", group);
		map.put("page", page);
		if (!perpage.equals(""))
			map.put("perpage", perpage);
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<Space> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				String data = jsonObject.optString("data");
				Gson gson = new GsonBuilder().serializeNulls().create();
				list = gson.fromJson(data, new TypeToken<List<Space>>() {
				}.getType());
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 1.16  好友分组接口
	 */
	public static List<Map<String, Object>> group() throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "friend");
		map.put("view", "groupname");
		map.put("m_auth", CacheService.getSpace().getmAuth());
		map.put("client", "android");
		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
		try {
			String json = HttpUtil.get(URL, map);
			JSONObject jsonObject = new JSONObject(json);
			if (jsonObject.getInt("error") == 0) {
				JSONArray data = jsonObject.optJSONArray("data");
				for (int i = 0; i < data.length(); i++) {
					JSONObject object = data.optJSONObject(i);
					Map<String, Object> mapPut = new HashMap<String, Object>();
					mapPut.put("gid", object.optString("gid"));
					mapPut.put("gname", object.optString("gname"));
					list.add(mapPut);
				}
			} else {
				throw new MyHttpException(jsonObject.optString("msgkey"),
						jsonObject.optString("msg"));
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
	
	/**
	 * 1.21便民列表接口
	 * 
	 * @param xiaoquid
	 * @param page
	 * @param perpage
	 * @return
	 * @throws MyHttpException
	 */
	public static List<Telephone> teleList(String xiaoquid, String page,
			String perpage) throws MyHttpException {
		Map<String, String> map = new HashMap<String, String>();
		map.put("do", "telephone");
		if (!page.equals(""))
			map.put("page", page);
		if (!perpage.equals(""))
			map.put("perpage", perpage);
		map.put("xiaoquid", xiaoquid);
		map.put("m_auth", "");
		map.put("client", "android");
		List<Telephone> list = null;
		try {
			String json = HttpUtil.get(URL, map);
			String data = new JSONObject(json).optString("data");
			Gson gson = new GsonBuilder().serializeNulls().create();
			list = gson.fromJson(data, new TypeToken<List<Telephone>>() {
			}.getType());
		} catch (JSONException e) {
			e.printStackTrace();
		}
		return list;
	}
}
